package com.ruoyi.data.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.data.domain.DataInventory;
import com.ruoyi.data.mapper.DataInventoryMapper;
import com.ruoyi.data.service.IDataInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 当前库存Service业务层处理
 *
 * @author zzp
 * @date 2022-10-03
 */
@Service
public class DataInventoryServiceImpl implements IDataInventoryService {
    @Autowired
    private DataInventoryMapper dataInventoryMapper;

    /**
     * 查询当前库存
     *
     * @param id 当前库存主键
     * @return 当前库存
     */
    @Override
    public DataInventory selectDataInventoryById(Long id) {
        return dataInventoryMapper.selectDataInventoryById(id);
    }

    /**
     * 查询当前库存列表
     *
     * @param dataInventory 当前库存
     * @return 当前库存
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<DataInventory> selectDataInventoryList(DataInventory dataInventory) {
        return dataInventoryMapper.selectDataInventoryList(dataInventory);
    }

    /**
     * 新增当前库存
     *
     * @param dataInventory 当前库存
     * @return 结果
     */
    @Override
    public int insertDataInventory(DataInventory dataInventory) {
        dataInventory.setCreateTime(DateUtils.getNowDate());
        return dataInventoryMapper.insertDataInventory(dataInventory);
    }

    /**
     * 修改当前库存
     *
     * @param dataInventory 当前库存
     * @return 结果
     */
    @Override
    public int updateDataInventory(DataInventory dataInventory) {
        dataInventory.setUpdateTime(DateUtils.getNowDate());
        return dataInventoryMapper.updateDataInventory(dataInventory);
    }

    /**
     * 批量删除当前库存
     *
     * @param ids 需要删除的当前库存主键
     * @return 结果
     */
    @Override
    public int deleteDataInventoryByIds(Long[] ids) {
        return dataInventoryMapper.deleteDataInventoryByIds(ids);
    }

    /**
     * 删除当前库存信息
     *
     * @param id 当前库存主键
     * @return 结果
     */
    @Override
    public int deleteDataInventoryById(Long id) {
        return dataInventoryMapper.deleteDataInventoryById(id);
    }

    /**
     * 查询会员商品可用库存
     *
     * @param stockUserId
     * @param goodId
     * @return
     */
    @Override
    public DataInventory selectDataInventoryByUserIdAndGoodId(Long stockUserId, Long goodId) {
        return dataInventoryMapper.selectDataInventoryByUserIdAndGoodId(stockUserId, goodId);
    }

    @Override
    public List<DataInventory> selectDataInventoryListByUserId(DataInventory inventory) {
        return dataInventoryMapper.selectDataInventoryListByUserId(inventory);
    }
}
